# iris数据集 AdaBoost 算法
import matplotlib.pyplot as plt
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import cross_val_score

from sklearn import datasets
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix

np.random.seed(2023)
iris = datasets.load_iris()
x_data = iris.data
y_data = iris.target

# 随机抽取30%的测试集##################################################
x_train, x_test, y_train, y_test = train_test_split(
    x_data, y_data, test_size=0.4)

print(x_train.shape,y_train.shape,x_test.shape,y_test.shape)

# 建立模型############################################################
model = AdaBoostClassifier(n_estimators=100)
model.fit(x_train, y_train)

# 输出结果############################################################
score=model.score(x_train, y_train)
print(score)
score=model.score(x_test, y_test)
print(score)

y_pred = model.predict(x_test)
print(y_pred)

print(classification_report(y_test, y_pred))
print(confusion_matrix(y_test, y_pred))